// pages/giftdetail/giftdetail.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: {},//礼物详情
    isHiddenMes1: true,
    gift_id:'',
    comment_list:[],//评论列表

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
   
   //获取详情
    this.getGiftDetail(options.id);

    var id = parseInt(options.id);
    that.setData({
      gift_id:id
    })

  //获取评论
  this.comments_list();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  /**
   *获取礼物详情数据 
   */
  getGiftDetail(id) {
    app.apiPost(app.apiList.giftdetail, {
      content:{
        id: id
      } 
    }, (res) => {
      console.log(res,'获取礼物详情数据');

      this.setData({
        detail: res.content
      })
    })
  },
  //获取礼物评论
  comments_list:function(){
    var that = this;
    app.apiPost(app.apiList.gift_review, {
      content: {
        pageNum:1,
        pageSize:20,
        giftId: that.data.gift_id
      }
    }, (res) => {
      console.log(res, '礼物评论')
      that.setData({
        comment_list: res.content.list
      })
    })
  },
  /**
   * 预览，查看大图
   */
  preview(e){
    wx.previewImage({
      urls: e.currentTarget.dataset.urls,
      current: e.target.dataset.url
    })
  },
  /**
   * 所有评论
   */
  all_review:function(){
    console.log('查看所有评论');
    var self = this;

    var obj = {};
    obj.siteId = self.data.gift_id;
    obj.recommendCount = self.data.detail.recommendCount;
    obj.reviewScores = self.data.detail.reviewScores;
    obj.like = self.data.detail.like;
    obj.likeCount = self.data.detail.likeCount;

    obj = JSON.stringify(obj);

    wx.navigateTo({
      url: '../giftcomment/giftcomment?obj=' + obj,
    })
  },
  /**
   * 特产店
   */
  specialty:function(e){
    var that = this;
    console.log(e, '详情礼物 列表', e.currentTarget.dataset.type);

    var t = e.currentTarget.dataset.type;
    t = parseInt(t);
    var obj = {};
    obj.id = that.data.gift_id;
    obj.t = t;
    obj = JSON.stringify(obj);

    wx.navigateTo({
      url: '../specialtystore/specialtystore?obj=' + obj,
    })
  },
  /**
   * 地图导航
   */
  toMap() {
    wx.navigateTo({
      url: '../nearsearch/nearsearch?type=gift'
    })
  },

})

// https://jingyan.baidu.com/album/5552ef47876faf518ffbc9d9.html?picindex=3 拨打电话功能